package com.lhf.fvscore.handler;


import cn.hutool.json.JSONUtil;
import com.lhf.fvscommon.result.Result;
import com.lhf.fvscommon.result.Status;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@Component()
public class AuthenticationEntryPoint implements org.springframework.security.web.AuthenticationEntryPoint {


    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException, ServletException {
        response.setCharacterEncoding("utf8");
        PrintWriter writer = response.getWriter();
        writer.println(JSONUtil.toJsonStr(Result.failure(Status.NO_LOGIN)));
    }
}